//
//  MovieDataViewController.m
//  UI - 豆瓣
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDataViewController.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"
#import "DateBaseSingleton.h"


@interface MovieDataViewController ()
@property(nonatomic, retain)UILabel *lable1;
@property(nonatomic, retain)UILabel *lable2;
@property(nonatomic, retain)UILabel *lable3;
@property(nonatomic, retain)UILabel *lable4;
@property(nonatomic, retain)UILabel *lable5;
@property(nonatomic, retain)UILabel *lable6;
@property(nonatomic, retain)UILabel *lable7;
@property(nonatomic, retain)UILabel *lable8;
@property(nonatomic, retain)UILabel *lable9;
@property(nonatomic, retain)UILabel *lable10;
@property(nonatomic, retain)UILabel *lable11;
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic, retain)UIScrollView *scrollView;

@end

@implementation MovieDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[DateBaseSingleton shareDataBase] createCollectTable];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.scrollView];
    [self.scrollView release];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 150)];
    [self.scrollView addSubview:self.imageView];
    [self.imageView release];
    
    _lable1 = [[UILabel alloc] initWithFrame:CGRectMake(140, 30, 60, 15)];
    _lable1.text = @"评分：";
    _lable1.font = [UIFont fontWithName:@"Papyrus" size:15];
    [self.scrollView addSubview:_lable1];
    [_lable1 release];
    
    
    
    _lable2 = [[UILabel alloc] initWithFrame:CGRectMake(190, 25, 60, 15)];
    _lable2.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable2];
    [_lable2 release];
    _lable3 = [[UILabel alloc] initWithFrame:CGRectMake(240, 25, 40, 15)];
    _lable3.text = @"(";
    _lable3.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable3];
    [_lable3 release];
    
    
    _lable4 = [[UILabel alloc] initWithFrame:CGRectMake(245, 25, 50, 15)];
    _lable4.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable4];
    [_lable4 release];
    
    _lable10 = [[UILabel alloc] initWithFrame:CGRectMake(280, 25, 100, 15)];
    _lable10.font = [UIFont systemFontOfSize:15];
    _lable10.text = @"人评论）";
    [self.scrollView addSubview:_lable10];
    [_lable10 release];
    
    
    _lable5 = [[UILabel alloc] initWithFrame:CGRectMake(140, 55, 215, 15)];
    _lable5.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable5];
    [_lable5 release];
    
    
    
    _lable6 = [[UILabel alloc] initWithFrame:CGRectMake(140, 85, 100, 15)];
    _lable6.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable6];
    [_lable6 release];
    
    _lable7 = [[UILabel alloc] initWithFrame:CGRectMake(140, 115, 100, 15)];
    _lable7.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable7];
    [_lable7 release];
    
    _lable11 = [[UILabel alloc] initWithFrame:CGRectMake(140, 145, 100, 15)];
    _lable11.font = [UIFont systemFontOfSize:15];
    [self.scrollView addSubview:_lable11];
    [_lable11 release];
    
    _lable1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 190, 215, 25)];
    _lable1.text = @"制作人";
    _lable1.font = [UIFont systemFontOfSize:18];
    [self.scrollView addSubview:_lable1];
    [_lable1 release];
    
    
    _lable8 = [[UILabel alloc] initWithFrame:CGRectMake(20, 210, 330, 60)];
    _lable8.font = [UIFont systemFontOfSize:14];
    _lable8.numberOfLines = 0;
    [self.scrollView addSubview:_lable8];
    [_lable8 release];
    
    _lable1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 280, 215, 25)];
    _lable1.text = @"电影情节";
    _lable1.font = [UIFont systemFontOfSize:18];
    [self.scrollView addSubview:_lable1];
    [_lable1 release];
    
    
    _lable9 = [[UILabel alloc] initWithFrame:CGRectMake(20, 320, 330, 300)];
//    _lable9.font = [UIFont systemFontOfSize:14];
    _lable9.numberOfLines = 0;
    [self.scrollView addSubview:_lable9];
    [_lable9 release];

    
   
    
    NSString *urlStr = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/searchmovie.php?movieId=%@", self.movieID];
    NSLog(@"==========================%@", urlStr);

    [AppTools getWithName:urlStr Block:^(id result) {
        NSMutableDictionary *dic = result;
        NSMutableDictionary *resultDic = [dic objectForKey:@"result"];
        NSURL *url = [NSURL URLWithString:[resultDic objectForKey:@"poster"]];
        [self.imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
        self.navigationItem.title = [resultDic objectForKey:@"title"];
        self.lable9.text = [resultDic objectForKey:@"plot_simple"];
        self.lable2.text = [resultDic objectForKey:@"rating"];
        self.lable4.text = [resultDic objectForKey:@"rating_count"];
        self.lable5.text = [resultDic objectForKey:@"release_date"];
        self.lable6.text = [resultDic objectForKey:@"runtime"];
        self.lable7.text = [resultDic objectForKey:@"genres"];
        self.lable8.text = [resultDic objectForKey:@"actors"];
        self.lable11.text = [resultDic objectForKey:@"film_locations"];
        [self.lable9 sizeToFit];
        CGFloat height = self.lable9.frame.origin.y + self.lable9.frame.size.height + 115;
        self.scrollView.contentSize = CGSizeMake(0, height);
    }];
    self.scrollView.showsVerticalScrollIndicator = NO;
//    self.scrollView.bounces = NO;
    
    
    
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_share.png"] style:UIBarButtonItemStyleDone target:self action:@selector(rightAction:)];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_back.png"] style:UIBarButtonItemStyleDone target:self action:@selector(leftAction:)];
    
    
    
}
- (void)leftAction: (UIBarButtonItem *)left{

    [self.navigationController popViewControllerAnimated:YES];
}
-(void)rightAction: (UIBarButtonItem *)right{
    
    
   NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"user"];
    
    if ([str  isEqual: @""]) {
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"未登录用户" message:@"不能收藏" preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }];
        [alertC addAction:action];
        
        [self presentViewController:alertC animated:YES completion:^{
        }];
    
    
    }
        NSMutableArray *array = [NSMutableArray array];
    array = [[DateBaseSingleton shareDataBase] selectCollect:str];
    
            if ([array containsObject:self.navigationItem.title]) {
                UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"已经被有品位的你收藏过了" preferredStyle:UIAlertControllerStyleActionSheet];
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                }];
                [alertC addAction:action];
                
                [self presentViewController:alertC animated:YES completion:^{
                    
                    
                }];
            
            
            
    }
            else{
                UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"收藏成功" message:@"亲还是有品位" preferredStyle:UIAlertControllerStyleActionSheet];
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

                    [[DateBaseSingleton shareDataBase] insertCollectMovieName:self.navigationItem.title userName:[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] movieId:self.movieID];
                    
                    
                    
                }];
                [alertC addAction:action];
                
                [self presentViewController:alertC animated:YES completion:^{
                    
                    
                }];
            }
    
    

    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
